#include "MapZoneIterator.h"
#include "MapZone.h"
#include "MapContent.h"

MapZoneIterator::MapZoneIterator(const std::vector< unsigned > &regions,
                           const MapContent *pMapContent)
    : mRegions(regions), mPos(0), mpMapContent(pMapContent)
{
    int index=0;
    if( !mRegions.empty() ) index = mRegions.at(0);
    mpCurrentMapZone = &mpMapContent->zones[index];
}

void MapZoneIterator::next()
{
    mpCurrentMapZone = 0;
    ++mPos;
    if (!mRegions.empty())
    {
        if (mPos != mRegions.size())
        {
            int index=mRegions.at(mPos);
            mpCurrentMapZone = &mpMapContent->zones[index];
        }
    }
    else
    {
        unsigned size = mpMapContent->mapWidth * mpMapContent->mapHeight;
        if (mPos != size )
        {
            mpCurrentMapZone = &mpMapContent->zones[mPos];
        }
    }
}

MapZone *MapZoneIterator::getPointerToCurrentMapZone()
{
    return mpCurrentMapZone;
}

bool MapZoneIterator::end()
{
    return (mpCurrentMapZone == 0);
}
